<!DOCTYPE html>
<html lang="zh">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        div {
            width: 600px;
            margin: 100px auto;
        }
        
        .message {
            display: inline-block;
            font-size: 12px;
            color: #999;
            background: url(images/mess.png) no-repeat left center;
            padding-left: 20px;
        }
        
        .wrong {
            color: red;
            background-image: url(images/wrong.png);
        }
        
        .right {
            color: green;
            background-image: url(images/right.png);
        }
    </style>
</head>

<body>
    <div class="register">
        <input type="text" class="ipt">
        <p class="message">请输入6~16位密码</p>
    </div>
   
    <script>
        // 1.获取元素
        var input1=document.querySelector('input');
        // message 消息 信息
        var message=document.querySelector('p');

        // 注册失去焦点事件
        input1.onblur=function(){
            // 获取到用户输入的内容
            var pwd=input1.value;
            if(pwd.length<=16 && pwd.length>=6){
                message.innerHTML='输入正确';
                message.className='message right';
            }else{
                message.innerHTML='输入的不符合要求';
                message.className='message wrong';
            }
            // console.log(pwd);
        }

    </script>
</body>

</html>